package com.cln.salesTaxes;

import java.math.BigDecimal;

import junit.framework.TestCase;

public class SalesTaxesTester extends TestCase {
	// Thanks again for your interest in ThoughtWorks. Enclosed are three
	// programming problems. We ask that you read all three descriptions
	// thoroughly then create a program to solve **ONE** of the problems. If you
	// choose to do more than one problem, we will choose and evaluate only one
	// of
	// your solutions.
	//	   
	// For the solution, we prefer you use either Java or C#. You may use
	// external libraries or tools for building or testing purposes.
	// Specifically, you may use JUnit or Ant to assist your development. For
	// security reasons, please do NOT submit your C# code as a .msi file.
	//	   
	// You may also include a brief explanation of your design and assumptions
	// along with your code.
	//	   
	// Please email your completed solution to CODE@THOUGHTWORKS.COM and
	// JXIA@THOUGHTWORKS.COM within three days. To expedite proper routing of
	// your code, please type the COUNTRY of the ThoughtWorks office you are
	// applying to (AUSTRALIA, UK, INDIA, CHINA, USA or CANADA) in the Subject
	// Line of your email.
	//	   
	// As a general rule, we allow three days from the date that you receive
	// this
	// letter to submit your code to CODE@THOUGHTWORKS.COM , but you may request
	// more time if needed. Since we may use your code as an interview tool,
	// ThoughtWorks reserves the right to postpone your technical interview if
	// your code is not received. If you have any questions about the code as it
	// relates to your interview process, please contact us at
	// CODE@THOUGHTWORKS.COM.
	//	   
	// ThoughtWorks would like the opportunity to offer you a challenging career
	// with our dynamic team. We wish you luck and look forward to receiving
	// your
	// response.
	//	   
	// Kind Regards,
	//	   
	//	   
	// ThoughtWorks Recruiting
	// CODE@THOUGHTWORKS.COM
	//	   
	// ==========
	//	   
	// INTRODUCTION TO THE PROBLEMS
	//	   
	// All problems below require some kind of input. You are free to implement
	// any mechanism for feeding input into your solution (for example, using
	// hard
	// coded data within a unit test). You should provide sufficient evidence
	// that your solution is complete by, as a minimum, indicating that it works
	// correctly against the supplied test data.
	//	   
	// PROBLEM TWO: SALES TAXES
	//	   
	// Basic sales tax is applicable at a rate of 10% on all goods, except
	// books,
	// food, and medical products that are exempt. Import duty is an additional
	// sales tax applicable on all imported goods at a rate of 5%, with no
	// exemptions.
	//	   
	// When I purchase items I receive a receipt which lists the name of all the
	// items and their price (including tax), finishing with the total cost of
	// the
	// items, and the total amounts of sales taxes paid. The rounding rules for
	// sales tax are that for a tax rate of n%, a shelf price of p contains
	// (np/100 rounded up to the nearest 0.05) amount of sales tax.
	//	   
	// Write an application that prints out the receipt details for these
	// shopping
	// baskets...
	// INPUT:
	//	   
	// Input 1:
	// 1 book at 12.49
	// 1 music CD at 14.99
	// 1 chocolate bar at 0.85
	//	   
	// Input 2:
	// 1 imported box of chocolates at 10.00
	// 1 imported bottle of perfume at 47.50
	//	   
	// Input 3:
	// 1 imported bottle of perfume at 27.99
	// 1 bottle of perfume at 18.99
	// 1 packet of headache pills at 9.75
	// 1 box of imported chocolates at 11.25
	//	   
	// OUTPUT
	//	   
	// Output 1:
	// 1 book : 12.49
	// 1 music CD: 16.49
	// 1 chocolate bar: 0.85
	// Sales Taxes: 1.50
	// Total: 29.83
	//	   
	// Output 2:
	// 1 imported box of chocolates: 10.50
	// 1 imported bottle of perfume: 54.65
	// Sales Taxes: 7.65
	// Total: 65.15
	//	   
	// Output 3:
	// 1 imported bottle of perfume: 32.19
	// 1 bottle of perfume: 20.89
	// 1 packet of headache pills: 9.75
	// 1 imported box of chocolates: 11.85
	// Sales Taxes: 6.70
	// Total: 74.68

	// *********************************************************************
	// Input 1:
	// 1 book at 12.49
	// 1 music CD at 14.99
	// 1 chocolate bar at 0.85

	// Output 1:
	// 1 book : 12.49
	// 1 music CD: 16.49
	// 1 chocolate bar: 0.85
	// Sales Taxes: 1.50
	// Total: 29.83
	public void testInput1() {
		IItem book = Item.createExemptItem("1 book", "12.49");
		IItem musicCD =  Item.createNormalItem("1 musicCD", "14.99");
		IItem chocolateBar = Item.createExemptItem("1 chocolateBar", "0.85");
		Basket basket = new Basket();
		basket.add(book);
		basket.add(musicCD);
		basket.add(chocolateBar);
		basket.calculate();
		assertTrue(0 == new BigDecimal("12.49").compareTo(book.getTotal()));
		assertTrue(0 == new BigDecimal("16.49").compareTo(musicCD.getTotal()));
		assertTrue(0 == new BigDecimal("0.85").compareTo(chocolateBar
				.getTotal()));
		assertTrue(0 == new BigDecimal("1.50")
				.compareTo(basket.getSalesTaxes()));
		assertTrue(0 == new BigDecimal("29.83").compareTo(basket.getTotal()));

	}

	// Input 2:
	// 1 imported box of chocolates at 10.00
	// 1 imported bottle of perfume at 47.50

	// Output 2:
	// 1 imported box of chocolates: 10.50
	// 1 imported bottle of perfume: 54.65
	// Sales Taxes: 7.65
	// Total: 65.15
	public void testInput2() {
		IItem importedChocolates = Item.createImportedExemptItem(
				"1 imported box of chocolates", "10.00");
		IItem importedPerfume = Item.createImportedNormalItem(
				"1 imported bottle of perfume", "47.50");
		Basket basket = new Basket();
		basket.add(importedChocolates);
		basket.add(importedPerfume);
		basket.calculate();
		
		assertTrue(0 == new BigDecimal("10.50").compareTo(importedChocolates.getTotal()));
		assertTrue(0 == new BigDecimal("54.65").compareTo(importedPerfume.getTotal()));
		assertTrue(0 == new BigDecimal("7.65")
				.compareTo(basket.getSalesTaxes()));
		assertTrue(0 == new BigDecimal("65.15").compareTo(basket.getTotal()));

	}

	// Input 3:
	// 1 imported bottle of perfume at 27.99
	// 1 bottle of perfume at 18.99
	// 1 packet of headache pills at 9.75
	// 1 box of imported chocolates at 11.25

	// Output 3:
	// 1 imported bottle of perfume: 32.19
	// 1 bottle of perfume: 20.89
	// 1 packet of headache pills: 9.75
	// 1 imported box of chocolates: 11.85
	// Sales Taxes: 6.70
	// Total: 74.68
	public void testInput3() {
		IItem importedPerfume = Item.createImportedNormalItem("1 imported bottle of perfume", "27.99");
		IItem perfume = Item.createNormalItem("1 bottle of perfume", "18.99");
		IItem headachePills = Item.createExemptItem("1 packet of headache pills", "9.75");
		IItem importedChocolates = Item.createImportedExemptItem("1 imported box of chocolates", "11.25");
		Basket basket = new Basket();
		basket.add(importedPerfume);
		basket.add(perfume);
		basket.add(headachePills);
		basket.add(importedChocolates);
		basket.calculate();
		
		assertTrue(0 == new BigDecimal("32.19").compareTo(importedPerfume.getTotal()));
		assertTrue(0 == new BigDecimal("20.89").compareTo(perfume.getTotal()));
		assertTrue(0 == new BigDecimal("9.75").compareTo(headachePills.getTotal()));
		assertTrue(0 == new BigDecimal("11.85").compareTo(importedChocolates.getTotal()));
		assertTrue(0 == new BigDecimal("6.70")
				.compareTo(basket.getSalesTaxes()));
		assertTrue(0 == new BigDecimal("74.68").compareTo(basket.getTotal()));

	}
}
